import { Key } from "../utils"
import type { ReactiverLike } from "../types"


export default class Subject {

    closed: boolean = false

    protected error:boolean = false

    binds: Array<ReactiverLike> = []

    parent?: Subject

    private _key!: Key

    protected bindClose:Boolean = false

    get key() {
        return this._key
    }

    private set key(val: Key) {
        this._key = val
    }


    constructor(bindContainer: ReactiverLike | null, key?: string) {
        this._key = Key.factory(key)
        if (bindContainer) {
            this.addHanlde(bindContainer)
        }
    }


     addHanlde(bindContainer: ReactiverLike) {
        
        this.binds.push(bindContainer)
        bindContainer.parent = this
    }

    protected proof(direct: boolean): boolean {
        if (direct) {
            return true
        } else {
            if (this.parent) {
                return false
            }
        }

        return true
    }

}